package com.example.yichuangyun.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Window;
import android.view.WindowManager;

import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;

import com.example.yichuangyun.R;

public abstract class BaseCommonDialog<T extends ViewDataBinding> extends Dialog {
    protected T mBinding;
    protected Context mContext;

    public BaseCommonDialog(Context context) {
        super(context, R.style.MyDialogStyle);
        this.mContext = context;
    }

    @Override
    protected void onStart() {
        super.onStart();
        setWidth();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

//        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
//        getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
//            @Override
//            public void onSystemUiVisibilityChange(int visibility) {
//                int uiOptions = View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
//                        //布局位于状态栏下方
//                        View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
//                        //全屏
////                        View.SYSTEM_UI_FLAG_FULLSCREEN |
//                        //隐藏导航栏
//                        View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
//                        View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
//                uiOptions |= 0x00001000;
//                getWindow().getDecorView().setSystemUiVisibility(uiOptions);
//            }
//        });

        mBinding = DataBindingUtil.inflate(LayoutInflater.from(getContext()), getLayoutId(), null, false);
        setContentView(mBinding.getRoot());
        this.getWindow().setGravity(getGravity());
        this.getWindow().setWindowAnimations(getAnimations());
        initView();
    }

    public void setWidth() {
        Window o = getWindow();
        WindowManager.LayoutParams lp = o.getAttributes();
        // x/y坐标
        // lp.x = 100;
        // lp.y = 100;
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        o.setAttributes(lp);
    }

    public void setY(int y) {
        Window o = getWindow();
        WindowManager.LayoutParams lp = o.getAttributes();
        // x/y坐标
        // lp.x = 100;
        // lp.y = 100;
        lp.y = y;
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        o.setAttributes(lp);
    }

    protected int getAnimations() {
        return R.style.main_menu_animStyle;
    }

    protected int getGravity() {
        return Gravity.BOTTOM;
    }

    protected abstract void initView();


    protected abstract int getLayoutId();

    @Override
    protected void onStop() {
        super.onStop();
    }
}